<template>
  <div class="detail-page">
    <div class="top">
      <div class="arrow" @click="$router.push('/article')">
        <van-icon name="arrow-left" size="20px" class="arrow-left"/>
      </div>
      <span class="title">文章详情</span>
    </div>
    <div class="user">
      <div class="avator">
        <img :src="article.aut_photo" alt="">
      </div>
      <div class="right">
        <div class="name">{{article.aut_name}}</div>
        <span class="time">4年前</span>
      </div>
      <div class="follow" @click="toggleFollow" :class="{active:article.is_followed}"><span ref="follow">关注</span></div>
    </div>
    <div class="info">
      <div class="title">{{article.title}}</div>
      <p class="content" v-html="article.content"></p>
    </div>
  </div>

</template>

<script>
import { getArticleDetail, followUser } from '@/api/article'
export default {
  name: 'detail-page',
  data () {
    return {
      article: {},
      channel_id: 0,
      timestamp: 1680856252672
    }
  },
  async created () {
    this.article = {}
    const { data } = await getArticleDetail(this.$route.params.id)
    this.article = data
    console.log(this.article)
  },
  methods: {
    async toggleFollow () {
      await followUser(this.article.id)
      this.article.is_followed = !this.article.is_followed
      this.$refs.follow.innerHTML = '已关注'
    }
  }
}
</script>

<style lang="less" scoped>
.top {
  width: 100%;
  height: 44px;
  position: relative;
  .arrow{
    width: 109px;
    height: 44px;
    line-height: 44px;
    .arrow-left{
      margin-left: 10px;
    }
  }
  .title {
    position: absolute;
    top: 10px;
    left: 150px;
    color: #1D2129;
    font-size: 17px;
  }
}
.user{
    display: flex;
    align-items: center;
    height: 78px;
    .avator{
      width: 30px;
      height: 30px;
      margin-left: 24px;
      img {
        width: 30px;
        height: 30px;
      }
    }
    .right{
      margin-left: 12px;
      .name{
        width: 180px;
        height: 26px;
        font-size: 14px;
        color: #1D2129;
      }
      .time{
        font-size: 12px;
        color: #B0B5BD;
      }
    }
    .follow {
      margin-left: 40px;
      width: 64px;
      height: 26px;
      background-color:  #F2F3F5;
      border-radius: 13px;
      text-align: center;
      line-height: 26px;
      span {
        font-size: 14px;
        color: #165DFF;
        font-weight: 400;
      }
      &.active {
        background-color:#165DFF;
        span {
          color: #FFFFFF;
        }
      }
    }
}
.info {
  margin-left: 24px;
  margin-right: 24px;
  .title {
    font-size: 18px;
    color: #1D2129;
    line-height: 28px;
  }
  .content {
    font-size: 16px;
    color: #4E5969;
    line-height: 26px;
    :deep(*) {
      max-width: 100%;
      overflow-x: scroll;
    }
  }
}
</style>
